
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:zfth/api/StateApi.dart';
import '../../api/AlarmApi.dart';
import '../../components/list/LCellListLogic.dart';
import '../../components/list/LCellListPage.dart';
import '../../utils/Settings.dart';
import '../../utils/Utils.dart';




class ThAlarmHandleListPage extends StatefulWidget{

  const ThAlarmHandleListPage({super.key});

  @override
  State<ThAlarmHandleListPage> createState() =>_ThAlarmHandleListPageState();

}

class _ThAlarmHandleListPageState extends State<ThAlarmHandleListPage> with AutomaticKeepAliveClientMixin{


  late final LCellListLogic cellListLogic;

  bool keepAlive = true;

  List queryFormAttributes = [
    {'field':'deviceRoom','label':'电房','component':'select','dictCode':Settings.dictCodes["配电室"],'condition':'eq'},
    {'field':'deviceNo','label':'采集终端','component':'select','dictCode':Settings.dictCodes["温湿度设备"],'condition':'eq'},
    {'field':'alarmType','label':'报警类型','component':'select','dictCode':Settings.dictCodes["报警类型"],'condition':'eq'},


  ];

  String tag = "thAlarmHandleList";
  @override
  void initState() {
    cellListLogic = Get.put(LCellListLogic(),tag: tag);
    cellListLogic.init(
        axiosUrl: AlarmApi.alarmLogListUrl,
        buildItemWidget: buildListItem,
        queryFormAttributes:queryFormAttributes,
        dictCodes:'${Settings.dictCodes["温湿度设备"]},${Settings.dictCodes["区域"]},${Settings.dictCodes["配电室"]},${Settings.dictCodes["报警类型"]},${Settings.dictCodes["报警结果类型"]}',
        initOrder:[{"field":'createTime',"val":'desc'}],
        initQuery:[{"field":'alarmAction',"val":'1'}],
        tag: tag
    );
    super.initState();
  }

  @override
  void dispose() {
    Get.delete<LCellListLogic>(tag: tag);
    super.dispose();
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => keepAlive;







  Widget buildListItem(item){
    return GestureDetector(
      onTap: () {
        Get.toNamed("/alarm/thAlarmHandleDetail",arguments: {"item":item,'tag':tag});
      },
      child: Card(
          elevation: 0.2,
          margin: const EdgeInsets.fromLTRB(10, 10, 10, 0),
          child: Stack(
            children: [
              IntrinsicHeight(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Expanded(
                        child:Padding(
                          padding: const EdgeInsets.only(top: 10,left: 10),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              Text("${item["deviceName"]}"),
                              // const SizedBox(width: 4,),
                              // Text(Utils.filterDictText(Settings.dictCodes["区域"],{},'${item["deviceRegion"]}'),style: const TextStyle(color: Colors.black38),),
                              // const SizedBox(width: 4,),
                              // Text(Utils.filterDictText(Settings.dictCodes["配电室"],{},'${item["deviceRoom"]}'),style: const TextStyle(color: Colors.black38),),
                            ],
                          ),
                        )

                    ),
                    Expanded(
                        child:Padding(
                          padding: const EdgeInsets.only(left: 10,top: 0,bottom: 0,right: 0),

                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [

                              Text(Utils.filterDictText(Settings.dictCodes["报警类型"],{},'${item["alarmType"]}')),
                              const Text("报警"),

                              const SizedBox(width: 14,),
                              Visibility(
                                  visible: item['alarmType']=="${Settings.constants['报警类型_温度']}",
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: [
                                      Image.asset("images/wendu.png",width: 16,height: 16,fit:BoxFit.contain ,),
                                    ],
                                  )
                              ),

                              Visibility(
                                  visible: item['alarmType']=="${Settings.constants['报警类型_湿度']}",
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: [
                                      Image.asset("images/shidu.png",width: 16,height: 16,fit:BoxFit.contain ,),
                                    ],
                                  )
                              ),

                              const SizedBox(width: 4,),
                              Text("${item["monitorVal"]??''}"),

                              const SizedBox(width: 14,),
                              Text(Utils.filterDictText(Settings.dictCodes["报警结果类型"],{},'${item["alarmResultType"]}')),



                            ],
                          ),
                        )

                    ),
                    Expanded(
                        child:Padding(
                            padding: const EdgeInsets.only(left: 10,top: 0,bottom: 0,right: 0),
                            child: Row(
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: [
                                  Image.asset("images/bianhao.png",width: 16,height: 16,fit:BoxFit.contain ,),
                                  const SizedBox(width: 4,),
                                  Text("${item["deviceNo"]}",style: const TextStyle(color: Colors.black38)),

                                  const SizedBox(width: 14,),
                                  Image.asset("images/shijian.png",width: 16,height: 16,fit:BoxFit.contain ,),
                                  Text("${item["createTime"]}",style: const TextStyle(color: Colors.black38)),
                                ]


                            )
                        )
                    )
                  ],


                ),
              ),
              const Positioned(
                right: 0,
                top:34,
                child:Icon(Icons.chevron_right,color: Colors.black38,),
              )
            ],
          )

      ),
    );
  }


  @override
  Widget build(BuildContext context) {
    super.build(context);
    return LCellListPage(tag:tag);
  }

}